package main.java.Thread;

import java.util.Random;
import java.util.Scanner;

public class homework {
    public static void main(String[] args) {
        Thw1 t1 = new Thw1();
        Thw2 t2 = new Thw2(t1);
        t1.start();
        t2.start();
    }


}


class Thw1 extends Thread{
    static Boolean running = true;
    @Override
    public void run() {
        Random r = new Random();
        while (running){
            System.out.println(r.nextInt(100));
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class Thw2 extends Thread{
    private Thw1 thw1;
    private final Scanner scanner = new Scanner(System.in);
    public Thw2(Thw1 thw1){
        this.thw1 = thw1;
    }

    @Override
    public void run() {
        while (true){
            char in = scanner.next().toUpperCase().charAt(0);
            if(in == 'Q'){
                Thw1.running = false;
                break;
            }
        }
    }
}

